﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace embed_window
{
    public partial class Form1 : Form
    {
        private int? id = null;
        private ExeImpaction exeIm;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = @"可执行程序(*.exe)|*.exe";
            ofd.ValidateNames = true;
            ofd.CheckPathExists = true;
            ofd.CheckFileExists = true;
            if (ofd.ShowDialog(this) == DialogResult.OK)
            {
                exeIm = new ExeImpaction();
                exeIm.ExecExe(panel1, ofd.FileName);
            }
        }

        private void panel1_Resize(object sender, EventArgs e)
        {
            exeIm?.FrmResize(panel1);
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            exeIm?.FrmClosing();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string exePath = @"D:\2Program\Typora\Typora.exe";
            exePath = @"D:\2Program\Notepad++\notepad++.exe";
            //exePath = "notepad.exe";
            exeIm = new ExeImpaction();
            exeIm.ExecExe(panel1, exePath);
            var watch = exeIm.EnumChildWindows();
            int index = 0;
            Console.WriteLine(Path.GetFileName(exePath) + "的子窗口：");
            foreach (var wnd in watch)
            {
                index++;
                Console.WriteLine(index + "：" + wnd);
            }
        }
    }
}
